package com.example.ch08;

import com.example.ch08.Entity.SysUser;
import com.example.ch08.Entity.User;
import com.example.ch08.Service.UserService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.*;
import org.springframework.test.context.junit4.SpringRunner;
import redis.clients.jedis.Jedis;

import javax.annotation.Resource;
import java.util.List;

@SpringBootTest
@RunWith(SpringRunner.class)
public class RedisTemplateTester {
    @Resource
    private UserService userService;
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Resource
    private RedisTemplate redisTemplate;


    @Test
    public void testObject(){
        SysUser user = new SysUser("hyl","88888");
        ValueOperations<String,SysUser> operations = redisTemplate.opsForValue();
        operations.set("user",user);

        SysUser tmp=  operations.get("user");
        System.out.println(tmp.getName());
    }

    @Test
    public void testHash(){
        //名称 键 值
        HashOperations<String,String,Object> hash = redisTemplate.opsForHash();
        hash.put("h3","name","张三");
        hash.put("h3","age",18);
        System.out.println(hash.get("h3","age"));
    }

    public void sun(){

    }

    @Test
    public void testList(){
        //名称 键 值
        ListOperations<String,Object> list = redisTemplate.opsForList();
        list.leftPush("lh1","张三");
        list.leftPush("lh1","李四");

        System.out.println(list.index("lh1",1L));
    }

    @Test
    public void ii(){
        List<User> list = userService.finAll(1);
        System.out.println(list.size());
    }
}
